package inscripciones.Utiles;


import java.io.PrintStream;
import java.sql.Connection;
import java.sql.DriverManager;

public class ConexionAlterna
{

    public static Connection conex;
    String Driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/inscripciones";
    String usuario = "root";
    String clave = "root";

    public ConexionAlterna(String IP, String nombrebase, String usuario, String clave) {
        this.url= "jdbc:mysql://"+IP+":3306/"+nombrebase;
        this.usuario=usuario;
        this.clave=clave;
    }

    

    public Connection conectar()
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            //conex = DriverManager.getConnection("jdbc:mysql://localhost:3306/sisvoto", "root", "root");
            conex = DriverManager.getConnection(url, usuario, clave);
        }
        catch(Exception e)
        {
            System.out.println((new StringBuilder("Error")).append(e).toString());
            conex = null;
        }
        return conex;
    }

    public void cerrar()
    {
        try
        {
            conex.close();
        }
        catch(Exception e)
        {
            System.out.println((new StringBuilder("error")).append(e).toString());
        }
    }
}
